package top.manbutech.activity.activitydemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {

    private EditText mUsername;
    private Button mLogin_btn;
    private EditText mPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        initView();

        mLogin_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                handlerLogin();
            }
        });
    }

    private void handlerLogin() {
        String username = mUsername.getText().toString();
        String password = mPassword.getText().toString();

        if (TextUtils.isEmpty(username)) {
            Toast.makeText(this,"用户名不能为空！",Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(this,"密码不能为空！",Toast.LENGTH_SHORT).show();
            return;
        }

        Intent intent = new Intent(this,RegisterResultActivity.class);
        intent.putExtra("username",username);
        intent.putExtra("password",password);
        startActivity(intent);
        //结束当前页面
        finish();
    }

    private void initView() {
        mUsername = (EditText) this.findViewById(R.id.username);
        mPassword = (EditText) this.findViewById(R.id.username);
        mLogin_btn = (Button) this.findViewById(R.id.login_btn);
    }
}
